<!DOCTYPE html>
<html>
<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }

        body {
            background: #000 url(./assets/兴达八厂/背景兴达.jpg) no-repeat left top;
            background-size: 100%;
        }
    </style>
    <script src='../custom/libs/echarts.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src='../conf/dateTime.js'></script>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src="../conf/confURL.js"></script>
    <script>
        dataModel = new ht.DataModel();
        graphView = new ht.graph.GraphView(dataModel);
        let deptCode = "XD1112";
        var url = domain + "/HT_DATA_EIGHT.getGlobalStatistics.do";
        var H = [];
        var Chart = [];
        var warn = [];
        let button = [];
        let pie1;
        let pie2;
        let lostpie;
        var onecar;
        var twocar;
        var threecar;
        var OEE;
        var MTBF;
        var MTTR;
        var data = [];
        function init() {
            graphView.addToDOM();
            ht.Default.xhrLoad('displays/智慧兴达/兴达八厂/设备监控/device_eightFactory.json', function (text) {
                var json = ht.Default.parse(text);
                if (json.title) document.title = json.title;
                dataModel.deserialize(json);
                graphView.fitContent(true);
                tag();
                getData2(deptCode);
                getData4(deptCode);
                getData5(deptCode);
                getData6(deptCode);
                getData7(deptCode);
                getData8(deptCode);
                getData1(deptCode, "XD111203");
                getData1(deptCode, "XD111204");
                getData3(deptCode, "OEE");
            });
            //页面时间刷新
            setInterval(function () {
                let dateTime = dataModel.getDataByTag("dateTime")
                let time = updateTime();
                dateTime.a('time', time);
            }, 1000);
            //车间维护维修数据自动切换
            var time1 =
                setInterval(function () {
                    if (button[0].a("visible") == true) {
                        cut1(twocar);
                        button[0].a("visible", false);
                        button[1].a("visible", true);
                        button[2].a("visible", false);
                    } else if (button[1].a("visible") == true) {
                        cut1(threecar);
                        button[0].a("visible", false);
                        button[1].a("visible", false);
                        button[2].a("visible", true);
                    } else if (button[2].a("visible") == true) {
                        cut1(onecar);
                        button[0].a("visible", true);
                        button[1].a("visible", false);
                        button[2].a("visible", false);
                    }
                }, 1000 * 5);
            //设备OEE/MTBF/MTTR数据自动切换
            var time2 =
                setInterval(function () { //饼图定时切换
                    if (button[3].a("visible") == true) {
                        cut2(MTBF);
                        button[3].a("visible", false);
                        button[4].a("visible", true);
                        button[5].a("visible", false);
                    } else if (button[4].a("visible") == true) {
                        cut2(MTTR);
                        button[3].a("visible", false);
                        button[4].a("visible", false);
                        button[5].a("visible", true);
                    } else if (button[5].a("visible") == true) {
                        cut2(OEE);
                        button[3].a("visible", true);
                        button[4].a("visible", false);
                        button[5].a("visible", false);
                    }
                }, 1000 * 5);
            //监听事件点击实现报表切换
            graphView.addInteractorListener(function (e) {
                if (e.kind === 'clickData') {
                    if (e.data._tag == 'button1') {
                        cut1(onecar);
                        button[0].a("visible", true)
                        for (let i = 1; i < 3; i++) {
                            button[i].a("visible", false)
                        }
                        clearInterval(time1)
                    }
                    else if (e.data._tag == 'button2') {
                        cut1(twocar);
                        button[1].a("visible", true);
                        button[0].a("visible", false);
                        button[2].a("visible", false);
                        clearInterval(time1)
                    }
                    else if (e.data._tag == 'button3') {
                        cut1(threecar);
                        button[2].a("visible", true)
                        for (let i = 0; i < 3 && i != 2; i++) {
                            button[i].a("visible", false)
                        }
                        clearInterval(time1)
                    }
                    else if (e.data._tag == 'button4') {
                        cut2(OEE);
                        button[3].a("visible", true);
                        button[4].a("visible", false);
                        button[5].a("visible", false);
                        clearInterval(time2)
                    }
                    else if (e.data._tag == 'button5') {
                        cut2(MTBF);
                        button[4].a("visible", true);
                        button[3].a("visible", false);
                        button[5].a("visible", false);
                        clearInterval(time2)
                    }
                    else if (e.data._tag == 'button6') {
                        cut2(MTTR);
                        button[5].a("visible", true);
                        button[3].a("visible", false);
                        button[4].a("visible", false);
                        clearInterval(time2)
                    }
                }
            });
        }
        function tag() {
            pie1 = dataModel.getDataByTag("pie1")
            pie2 = dataModel.getDataByTag("pie2")
            for (let i = 1; i < 5; i++) {
                Chart.push(dataModel.getDataByTag("Chart" + i))
            }
            for (let i = 1; i < 7; i++) {
                H.push(dataModel.getDataByTag("H" + i))
            }
            for (let i = 1; i < 7; i++) {
                warn.push(dataModel.getDataByTag("warn" + i))
            }
            for (let i = 1; i < 7; i++) {
                button.push(dataModel.getDataByTag("button" + i))
            }
            onecar = getData1(deptCode, "XD111203");
            twocar = getData1(deptCode, "XD111204");
            threecar = getData1(deptCode, "XD111205");
            OEE = getData3(deptCode, "OEE");
            MTBF = getData3(deptCode, "MTBF");
            MTTR = getData3(deptCode, "MTTR");
        }
        function cut1(repData) {
            if(repData.data != null && repData.data != undefined && repData.data != ''){
            pie1.a("name1", repData.data[0].name);
            pie1.a("name2", repData.data[1].name);
            pie1.a("name3", repData.data[2].name);
            pie1.a("value1", repData.data[0].value);
            pie1.a("value2", repData.data[1].value);
            pie1.a("value3", repData.data[2].value);
            pie2.a("name1", repData.data1[0].name);
            pie2.a("name2", repData.data1[1].name);
            pie2.a("value1", repData.data1[0].value);
            pie2.a("value2", repData.data1[1].value);
            }
        }
        function cut2(repData) {
            if(repData.data != null && repData.data != undefined && repData.data != ''){
            Chart[1].a("xAxis", repData.data.month)
            Chart[1].a("yAxis1", repData.data.one)
            Chart[1].a("yAxis2", repData.data.two)
            Chart[1].a("yAxis3", repData.data.three)
            }
        }
        //八厂设备维修/维护情况接口
        function getData1(code, work) {
            lostpie = dataModel.getDataByTag("lostpie")
            function err1() {
                warn[0].s("2d.visible", true)
                lostpie.s("2d.visible", false)
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQWXXHQKTJ",
                    deptCode: code,
                    workshopCode: work,
                },
                headers: request_headers,
                async: false,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[0].a("title", repData.totalTitle)
                        warn[0].s("2d.visible", false)
                        lostpie.s("2d.visible", true)
                        cut1(repData)
                    } else {
                        err1()
                    }
                },
                error: function (error) {
                    err1()
                }
            })
            return repData;
        }
        //设备故障停台数接口   
        function getData2(code) {
            function err2() {
                warn[1].s("2d.visible", true)
                Chart[0].s("2d.visible", false)
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQGZTTSTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[1].a("title", repData.totalTitle)
                        warn[1].s("2d.visible", false)
                        Chart[0].s("2d.visible", true)
                        Chart[0].a("xAxis", repData.data.month)
                        Chart[0].a("yAxis1", repData.data.one)
                        Chart[0].a("yAxis2", repData.data.two)
                        Chart[0].a("yAxis3", repData.data.three)
                    } else {
                        err2()
                    }
                },
                error: function (error) {
                    err2()
                }
            })
            return repData
        }
        //设备OEE/MTBF/MTTR接口
        function getData3(code, device) {
            let lostChart = dataModel.getDataByTag("lostChart")
            function err3() {
                warn[2].s("2d.visible", true)
                lostChart.s("2d.visible", false)
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQOEEMTBFRTJ",
                    deptCode: code,
                    deviceCode: device,
                },
                headers: request_headers,
                async: false,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[2].a("title", repData.totalTitle)
                        warn[2].s("2d.visible", false)
                        lostChart.s("2d.visible", true)
                        cut2(repData)
                    } else {
                        err3()
                    }
                },
                error: function (error) {
                    err3()
                }
            })
            return repData
        }
        //设备维修成本接口
        function getData4(code) {
            const shebei = dataModel.getDataByTag("shebei")
            const text = dataModel.getDataByTag("text")
            var led = [];
            for (let i = 1; i < 5; i++) {
                led.push(dataModel.getDataByTag("led" + i))
            }
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQWXCBTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[3].a("title", repData.totalTitle)
                        text.s("text", repData.title)
                        warn[3].s("2d.visible", false)
                        shebei.s("2d.visible", true)
                        led[0].a("number1", repData.data.feiyong[0])
                        led[0].a("number2", repData.data.feiyong[1])
                        led[0].a("number3", repData.data.feiyong[2])
                        led[1].a("number1", repData.data.zhanbi[0])
                        led[1].a("number2", repData.data.zhanbi[1])
                        led[1].a("number3", repData.data.zhanbi[2])
                        led[3].a("number", repData.number)
                    } else {
                        warn[3].s("2d.visible", true)
                        shebei.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    warn[3].s("2d.visible", true)
                    shebei.s("2d.visible", false)
                }
            })
            return repData
        }
        //设备故障率接口
        function getData5(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQGZLTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[4].a("title", repData.totalTitle)
                        warn[4].s("2d.visible", false)
                        Chart[2].s("2d.visible", true)
                        Chart[2].a("xdata", repData.data.xdata)
                        Chart[2].a("bar", repData.data.guzhanglv)
                        Chart[2].a("line", repData.data.biaozhun)
                    } else {
                        warn[4].s("2d.visible", true)
                        Chart[2].s("2d.visible", false)
                    }
                },
                error: function (error) {
                    warn[4].s("2d.visible", true)
                    Chart[2].s("2d.visible", false)
                }
            })
            return repData
        }
        //吨平报修统计接口
        function getData6(code) {
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_REPORT_EQDPNHTJ",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.visible == "true") {
                        H[5].a("title", repData.totalTitle)
                        warn[5].s("2d.visible", false)
                        Chart[3].s("2d.visible", true)
                        if (repData.data.xdata != "") {
                            Chart[3].a("xdata", repData.data.xdata)
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("bar", repData.data.dunpingbaoxiu)
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("line", repData.data.biaozhun)
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("line1", repData.data.chanliang)
                        }
                        if (repData.data.xdata != "") {
                            Chart[3].a("line2", repData.data.baoxiucishu)
                        }

                    } else {
                        warn[5].s("2d.visible", true)
                        Chart[3].s("2d.visible", false)
                    }
                },
                error: function (error) {
                    warn[5].s("2d.visible", true)
                    Chart[3].s("2d.visible", false)
                }
            })
            return repData
        }
        //中间3车间
        function getData7(code) {
            let text1 = dataModel.getDataByTag("text1");
            let text2 = dataModel.getDataByTag("text2");
            let text3 = dataModel.getDataByTag("text3");
            let work11 = dataModel.getDataByTag("work1-1");
            let work12 = dataModel.getDataByTag("work1-2");
            let work13 = dataModel.getDataByTag("work1-3");
            let work14 = dataModel.getDataByTag("work1-4");
            const work21 = dataModel.getDataByTag("work2-1");
            const work22 = dataModel.getDataByTag("work2-2");
            const work3 = dataModel.getDataByTag("work3");
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_ZZ_FC_MAP",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_EQ_ZZ_FC_MAP.visible == "true") {
                        work11.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work12.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work13.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work14.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work21.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work22.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        work3.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text1.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text2.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                        text3.s("label", repData.HT_EQ_ZZ_FC_MAP.urlMap);
                    }
                },
                error: function (error) {
                }
            });
            return repData
        }
        //返回按钮接口
        function getData8(code) {
            const backButton = dataModel.getDataByTag("backButton")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_EQ_FC_BUTTON_RETURN",
                    deptCode: code
                },
                headers: request_headers,
                async: true,
                success: function (res) {
                    repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_EQ_FC_BUTTON_RETURN.visible == "true") {
                        backButton.a("url", repData.HT_EQ_FC_BUTTON_RETURN.data.url)
                        backButton.s("2d.visible", repData.HT_EQ_FC_BUTTON_RETURN.visible)
                    }
                },
                error: function (error) {
                }
            })
            return repData
        }
    </script>
</head>

<body onload='setTimeout(init, 300)'>
</body>

</html>